package com.example.day_blog.mapper;

import com.example.day_blog.model.BlogInfo;
import com.example.day_blog.model.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author starsea
 * @date 2024-01-18 13:01
 */
@Mapper
public interface BlogInfoMapper {
    //获取blog列表
    @Select("SELECT * FROM blog_spring.blog where delete_flag=0 order by create_time desc")
    List<BlogInfo> queryBlogList();
    //根据博客id获取博客详情
   @Select("SELECT * FROM blog_spring.blog where id=#{id} and delete_flag=0")
    BlogInfo queryById(Integer id);
    //编辑博客
   @Update("update blog set title=#{title},content=#{content}where id=#{id} and delete_flag=0;")
    Integer updateBlog(BlogInfo blogInfo);
    //删除博客
   @Update("update blog set delete_flag=1 where id=#{id} ")
    Integer deleteBlog(Integer id);
    //添加博客
    @Insert("insert into blog (title,content,user_id,upvote) values (#{title},#{content},#{userId},#{upvote})")
    Integer insertBlog(BlogInfo blogInfo);
    //根据blogid获取博客信息
    @Select("SELECT * FROM blog_spring.blog where id=#{id}")
    BlogInfo queryByBlogId(Integer id);
    //根据用户di找用户写下的文章数
    @Select("select count(id) from blog where user_id=#{userId} and delete_flag=0;")
    Integer sumBlogNumber(Integer userId);
    //根据博客id查询出点赞数量
    @Select("select upvote from blog where id=#{id}")
    Integer upvote(Integer id);
    @Update("update blog set upvote=#{updvote}  where id=#{id} ")
    Integer upvoteBlog(Integer updvote,Integer id);
}
